package cn.ewan.order.controller;

import cn.ewan.order.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 通过订单系统，调用商品微服务根据id查询商品信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/buy/{id}")
    public Product buy(@PathVariable(value = "id") Long id) {

        Product product = restTemplate.getForObject("http://localhost:9001/product/findById/" + id, Product.class);

        return product;
    }
}